package com.keyboardr.gamerater;

import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

public class NewGroupDialogFragment extends DialogFragment {

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		final Dialog dialog = new Dialog(getActivity());
		dialog.setContentView(R.layout.new_group);
		dialog.setTitle(R.string.newGroup);

		Button okButton = (Button) dialog.findViewById(R.id.groupOKButton);
		okButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				((GroupContainer) getActivity()).addGroup(new Group(
						((TextView) dialog.findViewById(R.id.groupNameText))
								.getText(), ((Spinner) dialog
								.findViewById(R.id.ruleSetSpinner))
								.getSelectedItemPosition() == 0));
				dialog.dismiss();
			}

		});
		Button cancelButton = (Button) dialog
				.findViewById(R.id.groupCancelButton);
		cancelButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				dialog.cancel();
			}
		});
		dialog.getWindow().setLayout(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT);
		return dialog;
	}
}
